<template>
  <basic-container>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <div class="card-body">
        <avue-crud :data="applyData"
                   :option="option"
                   :page="page"
                   :table-loading="tableLoading"
                   @size-change="sizeChange"
                   @current-change="currentChange"
                   @search-change="searchChange"
                   @search-reset="searchReset"
        >
          <template slot-scope="scope" slot="menu">
            <div class="menu-title" @click.stop="editApplication(scope.row,scope.index)" v-if="scope.row.state=='0'">
              <i class="iconfont iconalter" style="color: #ec950a;"></i>
              <p class="menu-title-text">编辑</p>
            </div>
            <div class="menu-title" @click.stop="applicationCommit(scope.row,scope.index)" v-if="scope.row.state=='0'">
              <i class="iconfont iconview" style="color: #409EFF;"></i>
              <p class="menu-title-text">提交</p>
            </div>

            <!--下载赋码反馈单-->
            <div class="menu-title" @click.stop="getExportFeedbackSheet(scope.row,scope.index)"  v-if="scope.row.stage=='H'">
              <img src="img/download-blue.png" class="detail-data-img"/><span>下载</span>
            </div>

          </template>
        </avue-crud>
      </div>
    </div>
  </basic-container>
</template>
<script>
  import {projectRegisterTrack, projectCommit, projectDelete} from "@/api/planning/project";
  import {PROJECT_DIC} from '@/const/dict'

  import {getRegisterinfo,exportFeedbackSheet} from "@/api/registerinfo/registerinfo";
  import {filedownload} from "@/api/system";

  export default {
    name: "projectTrack",
    created(){
      window.detailApplication = this.detailApplication;
      this.getApplyList(this.page)

//      this.getRegisterinfoData();
    },
    data() {
      return {
        publicPath: process.env.BASE_URL,
        headerData: {
          title: '规划跟踪'
        },
        input: "",
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableLoading: false,
        applyData: [],
        option: {
          page: true,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          cellBtn: false,
          indexWidth:70,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          menuWidth:150,
          menu: true,
          keyId: "id",
          column: [
            {
              label: "规划名称",
              prop: "title",
              cell: true,
              formatter: function (row, value, label, column) {
                return '<a style="cursor: pointer;" onclick="detailApplication(\'' + row.registerinfoId + '\')">' + value + '</a>';
              }
            },{
              label: "规划名称",
              prop: "titleLike",
              cell: true,
              search: true,
              hide: true,
              formatter: function (row, value, label, column) {
                return '<a style="cursor: pointer;" onclick="detailApplication(\'' + row.registerinfoId + '\')">' + value + '</a>';
              }
            },
            {
              label: "申报(牵头)单位",
              prop: "orgName",
              width:150,
              cell: true
            },
            {
              label: "规划类型",
              prop: "category",
              type: "select",
              width: 120,
              search: true,
              dicData: PROJECT_DIC.CATEGORY,
              cell: true
            },
            {
              label: "联系人姓名",
              width: 120,
              prop: "contactName",
              cell: true
            }
          ]
        },
        titleLikeSearch:'',
        categorysSearch:'',

        registerinfoData: {
          relatedFiles:[],
        },
      };
    },
    methods: {
      getApplyList(page, params) {
        this.tableLoading = true;
        projectRegisterTrack(Object.assign({
          current: page.currentPage,
          size: page.pageSize
        },params)).then(response => {
          this.applyData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false
        })
      },
      // 提交
      applicationCommit(row, index) {
        this.$confirm("确定发起申请?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          // 提交代码
          projectCommit(row.registerinfoId).then(response => {
            if (response.data.code == '0') {
              this.$message({
                message: '提交成功！',
                type: 'success'
              });
              this.refreshChange();
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消提交'
          });
        });
      },
      /**
       * 刷新回调
       */
      searchReset() {
        this.titleLikeSearch = '';
        this.categorysSearch = '';
        let params = {
          titleLike:this.titleLikeSearch,
          categorys:this.categorysSearch,
        };
        this.getApplyList(this.page,params);
      },
      searchChange(params) {
        this.page.currentPage = 1
        this.getApplyList(this.page,this.dealSearchParam(params))
      },
      // 处理搜索过滤
      dealSearchParam(params){
        if(params.titleLike){
          params.titleLike = params.titleLike;
        }
        if(params.category){
          params.categorys = params.category;
        }
        this.titleLikeSearch=params.titleLike;
        this.categorysSearch=params.category;
        return params;
      },
      currentChange(currentPage) {
        var page = this.page;
        page.currentPage = currentPage;
        let params = {
          titleLike:this.titleLikeSearch,
          categorys:this.categorysSearch,
        };
        this.getApplyList(page,params);
      },
      sizeChange(pageSize) {
        var page = this.page;
        page.pageSize = pageSize;
        let params = {
          titleLike:this.titleLikeSearch,
          categorys:this.categorysSearch,
        };
        this.getApplyList(page,params);
      },
      // 编辑
      editApplication(row, index) {
        let src = `/regEdit/detail/-1`;
        this.$router.push({
          path: src,
          query: {
            registerinfoId: row.registerinfoId
          }
        })
      },
      // 查看
      detailApplication(registerinfoId){
        let src = `/tagReply/detail/${registerinfoId}`;
        this.$router.push({
          path: src
        })
      },
      // 删除
      delApplication(row, index) {
        this.$confirm("确定要删除该登记信息?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          // 提交代码
          projectDelete(row.registerinfoId).then(response => {
            if (response.data.code == '0') {
              this.$message({
                message: '删除成功！',
                type: 'success'
              });
              this.refreshChange()
            }
          })
        });
      },
      //下载赋码反馈单
      getExportFeedbackSheet(row,index) {
        this.$confirm("确定下载赋码反馈单吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.downloadFile(row.registerinfoId)
        })
      },
      // 附件下载
      downloadFile(registerinfoId) {
        exportFeedbackSheet(registerinfoId).then(response => {
          if (response.status == 200) {
            this.download(response.data, "规划立项赋码反馈单.pdf")
          }
        }).catch((error) => {
          this.$notify({
            title: "失败",
            message: "下载失败[" + error + "]",
            type: "error",
            duration: 2000
          });
        })
      },


      // 下载文件
      download(data, filename) {
        if (data == null) {

        } else {
          let url = window.URL.createObjectURL(new Blob([data]));
          let link = document.createElement('a');
          link.style.display = 'none';
          link.href = url;
          link.setAttribute('download', filename);
          document.body.appendChild(link);
          link.click()
        }
      },

    }
  };
</script>

<style lang="scss" scoped>
  .card-border {
    border: 1px solid #d2d2d2;

  }

  .card-body {
    padding: 10px;
  }

  .head-button .el-button {
    padding: 8px 15px;
  }

  .item-group {
    display: flex;
    flex-flow: row wrap;
    width: 100%;
  }

  .item-choose {
    margin-left: 48px;
    margin-top: 30px;
    border: 1px solid #dedbdb;
    -webkit-box-flex: 0;
    /*-ms-flex: 0 0 31%;*/
    width: 180px;
    height: 250px;
    border-radius: 3px;
  }

  .item-choose-img {
    height: 170px;
    text-align: center;
    vertical-align: middle;
    padding-top: 25px;
    background-color: #f1ecec;
  }

  .item-choose-label {
    text-align: center;
    height: 55px;
    line-height: 55px;
    font-size: 19px;
    font-weight: 600;
    color: #fff;
  }

  .item-choose-label-orange {
    background-color: #00b7ee;
  }

  .item-choose-label-primary {
    background-color: #f65c4c;
  }

  .item-choose-label-green {
    background-color: #86d46e;
  }

  .item-choose-label-yellow {
    background-color: #f8b551;
  }

  .isActive {
    border: 2px solid #66ae7b
  }
  /deep/.el-form-item__content {
    width: 50%;
    line-height: 40px;
    position: relative;
    font-size: 14px;
  }
</style>

